@isTest
private class TriggerReturnOrder_TestClass {

    static testMethod void myUnitTest()
    {
         Profile p = [select id from profile where name='System Administrator' or Name='系统管理员'];
        User uTsr = new User(alias='standtss',email='sduser@testorgss.com',emailencodingkey='UTF-8', lastname='Testeing',
        languagelocalekey='en_US',localesidkey='en_US',timezonesidkey='America/Los_Angeles',
        profileid=p.Id,Title__c='Sales Rep',FunctionDepartment__c='Trade Sales', username='stsers@testorg.com');
        insert uTsr;
        
        System.runAs(uTsr)
        {
            Product2 ps=new Product2();
            ps.Name='testProduct';
            ps.Pack_Size_C__c=6;
            insert ps;
            
            Product2 ps2=new Product2();
            ps2.Name='dfdfdfdf';
            ps2.Pack_Size_C__c=6;
            insert ps2;
            
            Account acc=new Account();
            acc.Name='test';
            acc.Channel__c='百货店';
            acc.Contact__c='aaa';
            acc.No_of_checkout__c=22;
           // acc.LastVisitedDate__c=System.today();
           // acc.LastVisitedDateBeforeLastVisitedMonth__c=System.today();
           // acc.LastDistributedDate__c=System.today();
            acc.ContactPhoneNumber__c='1234567456';
            insert acc;
            
            Account acc2=new Account();
            acc2.Name='tdfdfdft';
            acc2.Channel__c='百货店';
            acc2.Contact__c='aaa';
            acc2.No_of_checkout__c=22;
           // acc2.LastVisitedDate__c=System.today();
           // acc2.LastVisitedDateBeforeLastVisitedMonth__c=System.today();
           // acc2.LastDistributedDate__c=System.today();
            acc2.ContactPhoneNumber__c='1234567456';
            insert acc2;
            
            Distributor__c dis=new Distributor__c(Distributor_Code__c='wwwwwww',Name='test',Fax__c='111111',Address__c='ddddd',Phone__c='123344',Accepted_Order_Way__c='Fax',Email__c='aa@aa.com');
            insert dis;
            
            Routing_Plan_And_Visit__c tr=new Routing_Plan_And_Visit__c(Visit_Date__c=Date.today().addMonths(1));
            insert tr;
            
            RoutingPlan__c rp=new RoutingPlan__c();
            rp.RoutingPlanAndVisit__c=tr.Id;
            rp.OutletName__c=acc.Id;
            Date d=tr.Visit_Date__c;
            rp.StartDateTime__c=DateTime.newInstance(d.year(),d.month(),d.day(),8,8,8);
            rp.EndDateTime__c=DateTime.newInstance(d.year(),d.month(),d.day(),9,9,9);
            insert rp;
            
            Sales_Target__c st=new Sales_Target__c(Year__c=String.valueOf(d.year()),Month__c=String.valueOf(d.month()),
            NextSales__c=UserInfo.getUserId(),Sales_Target_Type__c='Distributed Outlet Number',
            SalesWeek1__c=1,SalesWeek2__c=1,SalesWeek3__c=1,SalesWeek4__c=1,SalesWeek5__c=1);
            insert st;
            
            In_Store_Visit__c vi=new In_Store_Visit__c();
            vi.RoutingPlanAndVisit__c=tr.Id;
            vi.SSYActivityAchievement__c=true;
            vi.OutletName_del__c=acc.Id;
            vi.Start_Time__c=DateTime.newInstance(d.year(),d.month(),d.day(),8,8,8);
            vi.End_Time__c=DateTime.newInstance(d.year(),d.month(),d.day(),9,9,9);
            vi.Main_Shelf_Facing__c=22;
            insert vi;
            
            SSYActivityExecutionTracking__c sae=new SSYActivityExecutionTracking__c(); 
            sae.OutletName__c=acc.Id; 
            sae.ExecutedSSY__c=1; 
            sae.SSYTarget__c=0; 
            sae.OwnerId=UserInfo.getUserId(); 
            sae.SalesMonth__c=Date.newInstance(d.year(),d.month(),1); 
            insert sae;
            
            In_Store_Visit__c vi2=new In_Store_Visit__c();
            vi2.RoutingPlanAndVisit__c=tr.Id;
            vi2.SSYActivityAchievement__c=true;
            vi2.OutletName_del__c=acc2.Id;
            vi2.Start_Time__c=DateTime.newInstance(d.year(),d.month(),d.day(),8,8,8);
            vi2.End_Time__c=DateTime.newInstance(d.year(),d.month(),d.day(),9,9,9);
            vi2.Main_Shelf_Facing__c=22;
            insert vi2;
            
            Inventory__c ven=new Inventory__c();
            ven.In_Store_Visit__c=vi.Id;
            ven.Product_Name__c=ps.Id;
            ven.Inventory__c=34;
            ven.Display__c=2;
            ven.Retail_Price__c=22;
            insert ven;
            
            Inventory__c ven2=new Inventory__c();
            ven2.In_Store_Visit__c=vi.Id;
            ven2.Product_Name__c=ps2.Id;
            ven2.Inventory__c=34;
            ven2.Display__c=2;
            ven2.Retail_Price__c=22;
            insert ven2;
            
            Inventory__c ven3=new Inventory__c();
            ven3.In_Store_Visit__c=vi.Id;
            ven3.Product_Name__c=ps2.Id;
            ven3.Inventory__c=34;
            ven3.Display__c=2;
            ven3.Retail_Price__c=22;
            insert ven3;
            
            Order__c ord=new Order__c();   
            ord.Outlet_name__c=acc.Id;
            ord.OrderType__c='退货';
            ord.In_Store_Visit__c=vi.Id;
            ord.Distributor_Name__c=dis.Id;
           // ord.Approval__c=false;
            ord.Address__c='asfsdfdf';
            insert ord;
           
            ord.Approval__c=true;
            update ord;
        }
    }
}